package com.yang.frost.raspberry.shiro.jwt;

import com.yang.frost.raspberry.util.JwtUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 10296
 * @date 2020/12/24
 * @Description: JWT 证书匹配
 */
public class JwtCredentialsMatcher  implements CredentialsMatcher {

    private Logger logger = LoggerFactory.getLogger(JwtCredentialsMatcher.class);


    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {

        try {
            String token = authenticationToken.getCredentials().toString();
            String salt = authenticationInfo.getCredentials().toString();
            return JwtUtil.verifyToken(token, salt);
        } catch (Exception e) {
            logger.error("JWT Token CredentialsMatch Exception:", e);
            e.printStackTrace();

        }


        return false;
    }
}
